<%@page import="com.lnsf.entity.Employee"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ page import="java.util.*,com.lnsf.util.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%-- <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt"%> --%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>修改页面</title>
<script type="text/javascript" src="scripts/jquery-1.7.2.js"></script>
</head>
<body>
<h2>Success</h2>
<script  type="text/javascript">
	$(document).ready(function(){
		
		$("#modifyEmpForm :submit").click(function(){
			
			$.ajax({
				type:"POST",
				url:"${pageContext.request.contextPath}/saveEmployeeByAjax",
				async:true,
				data:JSON.stringify({
					ename:$("#ename").val(),
					job:$("#job").val(),
					hiredate:$("#hiredate").val(),
					sal:$("#sal").val(),
					comm:$("#comm").val(),
					department:{deptNo:$("#departmentNo").val()}
				}),
				//dataType:"json",
				contentType: "application/json;charset=utf-8", //这个是发送信息至服务器时内容编码类型
				success:function(data){
					if(data == "update"){
						//alert(data);
						$("#message").html("成功"+data);
					}
					else
						$("#message").html("失败"+data);
				},
				error:function(){
					alert("添加失败");
				}
			});
			return false;
		});
	});
</script>

<br>
<form action="${pageContext.request.contextPath}/saveEmployee" id= "modifyEmpForm">
	编号：<input type="text" name="empNo" value="${requestScope.employeeInfo.empNo}" readonly="readonly"/><br>
	姓名：<input type="text" name="ename" value="${requestScope.employeeInfo.ename}"/><br>
	工作：<input type="text" name="job" value="${requestScope.employeeInfo.job}"/><br>
	 入职时间：<input type="text" name="hiredate" value="<%=DateUtil.getStringFromDate(((Employee)request.getAttribute("employeeInfo")).getHiredate())%>"/><br> 
	工资：<input type="text" name="sal" value="${requestScope.employeeInfo.sal}"/><br>
	奖金：<input type="text" name="comm" value="${requestScope.employeeInfo.comm}"/><br>
  	
  	 部门：
  		<select name="department.deptNo" >
  			<c:forEach items="${requestScope.departments}" var="dept">
  				<option  id="departmentNo" value="${dept.deptNo}" >${dept.dname}</option>
  			</c:forEach>
  		</select> 
	<input type= "submit" value = "提交"/>

</form>
<span id = "message"></span>
</body>
</html>
